package oop.controller.action.teststruct;

import java.util.List;

import oop.controller.action.DefaultAction;
import oop.data.TestStructure;
import oop.db.dao.TestStructureDAO;

public class ViewAction extends DefaultAction {
	@Override
	public void performImpl() throws Exception {
		
		try {
			int id = Integer.parseInt(request.getParameter("tsv_id"));
			List<TestStructure> structs = TestStructureDAO.fetchById(id);

			if (structs.isEmpty()) {
				error("Không tìm thấy cấu trúc đề thi có mã số " + id);
			} else {
				TestStructure testStruct = structs.get(0);
				title("Cấu trúc đề: " + testStruct.getName());
				request.setAttribute("teststruct", testStruct);
			}
		} catch (NumberFormatException ex) {
			error("Id không hợp lệ: " + request.getParameter("tsv_id"));
		}
	}
}
